package com.harmony.pilot.completion.service;

import com.harmony.pilot.common.dto.Diagnostic;
import com.harmony.pilot.completion.client.CompilationDatabaseClient;
import com.harmony.pilot.completion.service.impl.DiagnosticServiceImpl;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

import java.util.List;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;

/**
 * 诊断服务测试
 */
@ExtendWith(MockitoExtension.class)
class DiagnosticServiceTest {
    
    @InjectMocks
    private DiagnosticServiceImpl diagnosticService;
    
    @Mock
    private CompilationDatabaseClient compilationDatabaseClient;
    
    @Test
    void testCheckSyntax_UnmatchedBraces() {
        String code = "int main() { return 0; }"; // 正常代码
        List<Diagnostic> diagnostics = diagnosticService.checkSyntax(
            "test.cpp", code, "/test/project"
        );
        
        assertNotNull(diagnostics);
        // 应该没有错误
    }
    
    @Test
    void testCheckSyntax_MatchedBraces() {
        String code = "int main() { return 0;"; // 缺少右括号
        List<Diagnostic> diagnostics = diagnosticService.checkSyntax(
            "test.cpp", code, "/test/project"
        );
        
        assertNotNull(diagnostics);
        // 应该有错误
        assertFalse(diagnostics.isEmpty());
    }
    
    @Test
    void testCheckFile_Success() {
        String code = "int main() { return 0; }";
        List<Diagnostic> diagnostics = diagnosticService.checkFile(
            "test.cpp", code, "/test/project"
        );
        
        assertNotNull(diagnostics);
    }
}

